# coding: utf-8

from flask import Blueprint, render_template
from werkzeug.routing import BaseConverter

from app.utils import helper

user = Blueprint('user', __name__)


@user.route('/func_list/user_list/', methods=['GET', 'POST'])
def user_list():
    data_list = helper.fetch_all("SELECT id, user, nickname FROM user_info", [])
    return render_template('func_list/user_list.html', data_list=data_list)

# @user.route('/func_list/user_list/<int: user_id>')
# def find_user_by_id(user_id):
#     data = helper.fetch_one("select id, user, nickname from user_info WHERE id=%s", (user_id,))
#     return render_template('func_list/user_list.html', data_list=data)
#
#
# # 不加转换器类型，默认是普通字符串规则(除/之外)
# @user.route('/func_list/user_list/<username>')
# def find_user_by_name(username):
#     data = helper.fetch_one("select id, user, nickname from user_info WHERE nickname=%s", (username,))
#     return render_template('func_list/user_list.html', data_list=data)
#
#
# @user.route("/func_list/user_list/<re(r'1[34578]\d{9}'):mobile>")
# def find_user_by_mobile(mobile):
#     data = helper.fetch_one("select id, user, nickname from user_info WHERE mobile=%s", (mobile,))
#     return render_template('func_list/user_list.html', data_list=data)
#
#
# class RegexConverter(BaseConverter):
#     """自定义转换器"""
#
#     def __init__(self, url_map, regex):
#         super(RegexConverter, self).__init__(url_map)
#         self.regex = regex

# # 将自定义的转换器添加到flask的应用中
# app.url_map.converters["re"] = RegexConverter
